import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


const routes = [
  {
    path: '/',
    name: 'template',
    component: () => import('@/views/Template.vue'),
  },
  {
    path: '/paperdetail/:id',
    // redirect: 'template',
    name: 'PaperDetail',
    component:() => import('@/views/PaperDetail'),
  },
  {
    path: '/notification',
    // redirect: 'template',
    name: 'Notification',
    component:() => import('@/views/Notification'),
  },
  {
    path: '/searchResults',
    name: 'searchResults',
    component: () => import('@/views/SearchResults.vue'),
  },
  {
    path: '/searchCard',
    name: 'searchCard',
    component: () => import('@/views/search/SearchCard.vue'),
  },
  {
    path: '/researcherCard',
    name: 'researcherCard',
    component: () => import('@/views/search/ResearcherCard.vue'),
  },
  {
    path: '/userCard',
    name: 'userCard',
    component: () => import('@/components/UserCard.vue'),
  },
  {
    path: '/graph',
    name: 'graph',
    component: () => import('@/views/force-directed/graph.vue'),
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('@/views/Template.vue'),
  },
  {
    path: '/dashboard',
    name: 'dashboard',
    component: () => import('@/views/dashboard/Dashboard.vue'),
  },
  {
    path: '/typography',
    name: 'typography',
    component: () => import('@/views/typography/Typography.vue'),
  },
  {
    path: '/icons',
    name: 'icons',
    component: () => import('@/views/icons/Icons.vue'),
  },
  {
    path: '/cards',
    name: 'cards',
    component: () => import('@/views/cards/Card.vue'),
  },
  {
    path: '/simple-table',
    name: 'simple-table',
    component: () => import('@/views/simple-table/SimpleTable.vue'),
  },
  {
    path: '/form-layouts',
    name: 'form-layouts',
    component: () => import('@/views/form-layouts/FormLayouts.vue'),
  },
  {
    path: '/settings',
    name: 'account-settings',
    component: () => import('@/views/pages/account-settings/AccountSettings.vue'),
  },
  {
    path: '/application/search',
    name: 'application-search',
    component: () => import('@/views/pages/scholar-application/ScholarApplication.vue'),
  },
  {
    path: '/application/bind/:id',
    name: 'application-bind',
    component: () => import('@/views/pages/scholar-application/ScholarBind.vue'),
    meta: {
      layout: 'full'
    }
  },
  {
    path: '/personal',
    name: 'personal-center',
    component: () => import('@/views/pages/personal-center/PersonalCenter.vue'),
    children: [
      {
        path: "",
        redirect: { name: "personal-follows" }
      },
      {
        path: "follows",
        name: "personal-follows",
        component: () => import(
          '@/views/pages/personal-center/PersonalFollows.vue'),
      },
      {
        path: "stars",
        name: "personal-stars",
        component: () => import(
          '@/views/pages/personal-center/PersonalStars.vue'),
      },
      {
        path: "domains",
        name: "personal-domains",
        component: () => import("@/views/pages/personal-center/PersonalDomains.vue"),
      },
      {
        path: "chat",
        name: "personal-chat",
        component: () => import("@/views/pages/personal-center/PersonalChat.vue"),
      },
      {
        path: "history",
        name: "personal-history",
        component: () => import(
          '@/views/pages/personal-center/PersonalHistory.vue'),
      }
    ]
  },
  {
    path: '/rank',
    name: 'rank',
    component: () => import('@/views/ranks/Rank.vue'),
  },
  {
    path: '/admin',
    name: 'admin',
    component: () => import('@/views/admin/Admin.vue'),
  },
  {
    path: '/profile/:scholar',
    name: 'profile',
    component: () => import('@/views/profiles/AcademicProfile.vue'),
    meta: {
      layout: 'full',
    }
  },
  {
    path: '/profile',
    name: 'non_profile',
    component: () => import('@/views/pages/scholar-application/ScholarApplication.vue'),
  },
  {
    path: '/login',
    name: 'pages-login',
    component: () => import('@/views/pages/Login.vue'),
    meta: {
      layout: 'blank',
    },
  },
  {
    path: '/pages/register',
    name: 'pages-register',
    component: () => import('@/views/pages/Register.vue'),
    meta: {
      layout: 'blank',
    },
  },
  {
    path: '/error-404',
    name: 'error-404',
    component: () => import('@/views/Error.vue'),
    meta: {
      layout: 'blank',
    },
  },
  {
    path: '*',
    redirect: 'error-404',
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

export default router
